///////////////////////////////////////////////////////////////////////////////////////////////////
/// \file formic/test_driver/main.cpp
///
/// \brief   implementation file for the test driver program used to check that tests succeeded
///
///////////////////////////////////////////////////////////////////////////////////////////////////

#include <string>
#include <cstdlib>
#include <iostream>

#include <boost/format.hpp>

#include<formic/exception.h>
#include<formic/test_driver/utilities.h>

int main(int argc, char ** argv) {

  //for (int i = 0; i < argc; i++)
  //  std::cout << argv[i] << std::endl;
  //return EXIT_SUCCESS;

  // initialize a flag to tell if any tests failed
  bool success = true;

  // run tests based on command line arguments
  int count = 1;
  while (count < argc) {

    // get the command line option option
    const std::string option(argv[count++]);

    // check a floating point result
    if ( option == std::string("-compare_float") ) {

      const int nargs = 6;
      if ( count + nargs > argc )
        throw formic::Exception("-compare_float option requires %i arguments, only %i given") % nargs % (argc-count);

      const std::string float_name(argv[count++]);
      const std::string file_name(argv[count++]);
      const std::string search_string(argv[count++]);
      const int occurance = std::atoi(argv[count++]);
      const double target_value = std::atof(argv[count++]);
      const double tolerance = std::atof(argv[count++]);

      const bool result = formic::test::compare_float(float_name, file_name, search_string, occurance, target_value, tolerance, true);
      success = success && result;

    // unknown option
    } else {

      throw formic::Exception("test_driver was given an unknown option:  %s") % option;

    }

  }

  // signal failure if a test was unsuccessful
  if (!success)
    return EXIT_FAILURE;

  // otherwise, return a successful exit code
  return EXIT_SUCCESS;

}
